package udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @author wxc
 * @date 2021年09月15日 10:45
 */
public class ClientB {
    public static void main(String[] args) {
        DatagramSocket socket = null;
        try {
            socket = new DatagramSocket(9988);
            // UDP最大64 KB
            byte[] receiveData = new byte[64 * 1024];
            DatagramPacket datagramPacket = new DatagramPacket(
                    receiveData, receiveData.length);

            socket.receive(datagramPacket);
            String s = new String(datagramPacket.getData(), 0, datagramPacket.getLength());
            System.out.println(s);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (socket != null) {
                socket.close();
            }
        }

    }
}
